package net.lzzy.practices;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
 * @author Lenovo
 */
@Component
public class PracitcesMvcConfiguer implements WebMvcConfigurer {
    @Value("${user.pic}")
    private String picPath;
    @Value("${pic.size}")
    private int maxPiceSize;
    @Bean
    public CommonsMultipartResolver multipartResolver() {
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setMaxUploadSizePerFile(maxPiceSize);
        return resolver;
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("file:/"+picPath,
                "classpath:/webapp/",
                "classpath:/static/",
                "classpath:/public/");
        //通过配置URL规则和要查找的位置，Spring MVC在处理静态资源的请求时，按照指定的路径规则从指定的位置查找相应的文件
    }
}
